package tail.utils;

import java.util.logging.Level;

/**
 * Provides a common means of logging error, info and warning messages across
 * classes.
 * @author Michael Sena
 * @version 1.1
 */
public final class Logger {

    /** Private constructor. */
    private Logger() {
    }

    /**
     * Creates a logs a message.
     * @param cls Originating class of the log message
     * @param message Description of the message
     * @param severity Severity level of the log message
     * @param e Exception that was raised
     */
    public static void log(final Object cls, final String message,
        final Level severity, final Exception e) {
        String className = null;
        if (cls instanceof String) {
            className = (String) cls;
        } else {
            className = cls.getClass().getName();
        }
        if (e == null) {
            java.util.logging.Logger.getLogger(className)
                .log(severity, message);
        } else {
            java.util.logging.Logger.getLogger(className)
                .log(severity, message, e);
        }
    }

    /**
     * Creates a logs a message.
     * @param cls Originating class of the log message
     * @param message Description of the message
     * @param e Exception that was raised
     */
    public static void log(final Object cls, final String message,
        final Exception e) {
        log(cls, message, Level.SEVERE, e);
    }

    /**
     * Creates a logs a message.
     * @param cls Originating class of the log message
     * @param message Description of the message
     */
    public static void log(final Object cls, final String message) {
        log(cls, message, Level.SEVERE, null);
    }

    /**
     * Creates a logs a message.
     * @param cls Originating class of the log message
     * @param message Description of the message
     * @param severity Severity level of the log message
     */
    public static void log(final Object cls, final String message,
        final Level severity) {
        log(cls, message, severity, null);
    }
}
